var liaojieLanJu=({
	saveMessage : function (){
		$.ajax({
			type : "POST",
			dataType : 'json',
			url : "../user/isLogin.do",
			data : {
			},
			success : function(data) {
				if(data.success){
					var content=$("#content").val();
					if(content ==""){
						$$.toast("请输入留言内容");
						return false;
					}
					$.ajax({
						type : "POST",
						dataType : 'json',
						url : "../introduce/saveMessage",
						data : {
							message:content,
							type :0,
							userCode : ""
						},
						success : function(data) {
							if(data.success){
								$$.alert("提交成功", function(){
									liaojieLanJu.getMessageList();
									$("#content").val("");
									$(".num").text(0);
									});
							}
						}
					});
				}else{
					 $$.alert(data.msg, function () {
				          window.location.href="./login.html?url="+encodeURIComponent(window.location.href);
				    });
				}
			}
		});
	},
	getMessageList : function (){
		var message=$("#message").val();
		$.ajax({
			type : "POST",
			dataType : 'json',
			url : "../introduce/getMessageList",
			data : {
				type :0
			},
			success : function(data) {
				var html="";
				if(data.rows!=null){
					for(var i=0;i<data.rows.length;i++){
					html+="<div class=\"list-block media-list\"><ul>";
			        html+=" <li class=\"item-content\">";
			        html+="<div class=\"item-media\">"; 
			        html+=" <img src=\"../images/headboy.png\" width=\"44\">";   
			        html+="</div>  <div class=\"item-inner\"> <div class=\"item-title-row\">";   
			        html+="<div class=\"item-title\">"+data.rows[i].createNmae+"</div> </div>";
			        html+=" <div class=\"item-subtitle\" style='white-space: normal;text-overflow: inherit;'>"+data.rows[i].message+"</div>";
			        html+="</div></li></ul> </div>";      
			      }
					$("#liuyan").html(html);
				}
			}
		});
		
	},
	toLink : function (txt,tagrt){
		var phone=liaojieLanJu.getCookie("phone");
		$.ajax({
			type : "POST",
			dataType : 'json',
			url : "../user/isLogin.do",
			data : {
				"phone": liaojieLanJu.getCookie("phone")
			},
			success : function(data) {
				console.log(data);
				if(data.success){
					if(data.user.flag!='1'){
						 $$.toast("抱歉，该功能只针对业主开放"); 
						 return false;
					 }else{
						 if(data.user.idCard==null){
							 data.msg="您还实名认证，请认证后继续吧";
							 $$.alert(data.msg, function () {
								 window.location.href="./authentication.html?phone="+data.user.phone;
						    });
						 }else{
							 document.location.href = "./" + txt;
						 }
						
					 }
					
				}else{
					data.msg="您还没登录，请登录再操作吧";
					 $$.alert(data.msg, function () {
						 window.location.href="./login.html?url="+encodeURIComponent(window.location.href);
				    });
				}
			}
		});
		
	},
	getAllCaseList : function (){
		$.ajax({
			type : "POST",
			dataType : 'json',
			url : "../wx_yezhucase/getAllCaseList.do",
			data : {
				limit : 5
			},
			success : function(data) {
					console.log(data);
					var html ="";
					if(data.rows !=null && data.rows.length>0){
						for(var i=0;i<data.rows.length;i++){
							var endDate = (new Date(data.rows[i].createTime)).getTime(); //得到毫秒数  
							var newDate = new Date(endDate ); //得到普通的时间了 
							html+="<a  href=\"./newsDetails.html?id="+data.rows[i].id+"\"><ul > <li class=\"item-content\">";
							html+="<div class=\"item-media\">";
							html+=" <img src="+data.rows[i].img_url+" width=\"110\" height=\"100\"></div>";
							html+=" <div class=\"item-inner\">";
							html+="<div class=\"item-title-row\">";
							html+="<div class=\"item-title\" style=\"white-space: inherit;color:#000\" >"+data.rows[i].title+"</div> </div>";	
							html+="<div class=\"item-subtitle\" style=\"color:#e0e0e0\">"+newDate.getFullYear()+"/"+newDate.getDay()+"</div> </div></li></ul></a>";
						}
						
					}else{
						
					}
					$(".case").html(html);
					
			}
		});
	},
	getCookie : function (name) 
	{ 
	    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
	 
	    if(arr=document.cookie.match(reg))
	 
	        return unescape(arr[2]); 
	    else 
	        return null; 
	} 
});

$(function(){
	var tab = $.getUrlParam('tab');
	if(tab=="tab1"){
		$(".tab-link").removeClass("active");
		$(".tab-link").eq(0).addClass("active");
		$("#"+tab).addClass("active");
		$("#tab2").removeClass("active");
		$("#tab3").removeClass("active");
		sharLink = "http://lanjushiye.com.cn/LanJuPublic/jsp/liaojieLanJu.html?tab=tab1";
		title = "蓝居管家--蓝居简介";
		desc = "蓝居实业提供房屋托管、免佣租房、个性家装、保洁服务";
	}else if(tab=="tab2"){
		$(".tab-link").removeClass("active");
		$(".tab-link").eq(1).addClass("active");
		$("#"+tab).addClass("active");
		$("#tab1").removeClass("active");
		$("#tab3").removeClass("active");
		sharLink = "http://lanjushiye.com.cn/LanJuPublic/jsp/liaojieLanJu.html?tab=tab2";
		title = "蓝居管家--托管介绍";
		desc = "蓝居房屋托管安全可靠，收益快稳，省时省事";
	}else{
		$(".tab-link").removeClass("active");
		$(".tab-link").eq(2).addClass("active");
		$("#"+tab).addClass("active");
		$("#tab1").removeClass("active");
		$("#tab2").removeClass("active");
		sharLink = "http://lanjushiye.com.cn/LanJuPublic/jsp/liaojieLanJu.html?tab=tab3";
		title = "蓝居管家--租房介绍";
		desc = "蓝居租房无需中介费、个性定制房屋、专业保洁服务";
	}
	
	liaojieLanJu.getMessageList();
	liaojieLanJu.getAllCaseList();
	$.ajax({
		url : "../introduce/getIntroduceDetail.do",
		data : {
			id :1
			},
		type : "POST",
		dataType : 'json',
		cache : false,
		success : function(data) {
		if(data.rows !=null){
			$("#jianjie").html(data.rows.introduce);
		}
		}
	})
});
